/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.Address;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class AddressDAO extends AbstractDAO implements IDAO<Address, Integer> {

    @Override
    public List<Address> getAll() throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int updateSingle(Address t, Integer id) throws Exception {
         String sql = "update address set " +
"            emp_id = ?, province_id = ?, " +
"            shipcode = ?, address_no = ?, soi = ?, road = ?, tambon = ?, ampher = ?, home_tel = ?, mobile = ?"
                 + " where address_id = ? ";
        
        return this.getCon().update(sql,t.getEmpID(),t.getProvinceID(),
                t.getShipcode(),t.getAddressNo(),t.getSoi(),t.getRoad(),t.getTambon(),t.getAmpher(),t.getHomeTel(),t.getMobile(),id);
  
    }

    @Override
    public int deleteSingle(Address t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(Address t) throws Exception {
        String sql = "INSERT INTO address(" +
"            address_name, emp_id, province_id, " +
"            shipcode, address_no, soi, road, tambon, ampher, home_tel, mobile) " +
"    VALUES ( ?, ?,  ?, " +
"            ?, ?, ?, ?, ?, ?, ?, ?);";
        
        return this.getCon().add(sql,t.getAddressName(),t.getEmpID(),t.getProvinceID(),
                t.getShipcode(),t.getAddressNo(),t.getSoi(),t.getRoad(),t.getTambon(),t.getAmpher(),t.getHomeTel(),t.getMobile());
    }

    @Override
    public Address getById(Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    
    
    public Address getByEmpId(String id) throws Exception {
        String sql = "select * from address where emp_id = ?";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        Map<String , Object> map = this.getCon().querySingle(sql,id);
        Address ad = new Address();
        ad.setAddressID(Integer.parseInt(map.get(Address.field_address_id).toString()));
        ad.setAddressName(map.get(Address.field_address_name).toString());
        ad.setAmpher(map.get(Address.field_ampher).toString());
        ad.setEmpID(map.get(Address.field_emp_id).toString());
        ad.setHomeTel(map.get(Address.field_home_tel).toString());
        ad.setMobile(map.get(Address.field_mobile).toString());
        ad.setProvinceID(Integer.parseInt(map.get(Address.field_province_id).toString()));
        ad.setRoad(map.get(Address.field_road).toString());
        ad.setShipcode(map.get(Address.field_shipcode).toString());
        ad.setSoi(map.get(Address.field_soi).toString());
        ad.setTambon(map.get(Address.field_tambon).toString());
        ad.setAddressNo(map.get(Address.field_address_no).toString());
        return ad;
    }
    
    
    
}
